<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	template="/templates/modeloSistema.xhtml"
	xmlns:stella="http://stella.caelum.com.br/faces2">

	<ui:define name="menu">
		<ui:include src="/includes/menuPrincipal.xhtml" />
	</ui:define>

	<ui:define name="conteudo">

		<f:event listener="#{MBLocal.carregarLocais}" type="preRenderView" />

		<!-- Inicio do DataTable -->

		<h:form prependId="false" id="frmLocListagem">
			<p:dataTable id="tblLocListagem" widgetVar="tabelaLocListagem"
				value="#{MBLocal.listaLocal}" var="local"
				emptyMessage="Nenhum registro encontrado." paginator="true" rows="5"
				rowsPerPageTemplate="5,10,15,20"
				filteredValue="#{MBLocal.localFiltrados}">

				<f:facet name="header">
					<h:outputText value="Locais Cadastrados" />
				</f:facet>

				<p:column headerText="Código" filterBy="#{local.codigo}"
					sortBy="#{local.codigo}">
					<h:outputText value="#{local.codigo}" />
				</p:column>

				<p:column headerText="Descrição" filterBy="#{local.descricao}"
					sortBy="#{local.descricao}">
					<h:outputText value="#{local.descricao}" />
				</p:column>

				<p:column headerText="Inativo" >
					<h:outputText value="#{local.inativo}" />
				</p:column>



				<p:column headerText="Operações">
					<p:commandButton icon="ui-icon-trash" value="Excluir"
						oncomplete="PF('dlgLocExcluir').show();"
						update=":frmLocExcluir:pnlLocExcluir">
						<f:setPropertyActionListener value="#{local}"
							target="#{MBLocal.localDomain}" />

					</p:commandButton>

					<p:commandButton icon="ui-icon-pencil" value="Editar"
						oncomplete="PF('dlgLocAlterar').show();"
						update=":frmLocAlterar:pnlLocAlterar">
						<f:setPropertyActionListener value="#{local}"
							target="#{MBLocal.localDomain}" />
					</p:commandButton>
				</p:column>

				<f:facet name="footer">
					<p:commandButton value="Novo" 
					actionListener="#{MBLocal.prepararNovo}"
					oncomplete="PF('dlgLocNovo').show();"
						update=":msgGlobal :frmLocNovo:pnlLocNovo" />
				</f:facet>
			</p:dataTable>
		</h:form>
		<!-- Fim do DataTable -->

		<!-- Inicio do Dialogo de Inclusão -->
		<p:dialog widgetVar="dlgLocNovo" closable="true" draggable="false"
			closeOnEscape="true" resizable="false" appendTo="@(body)"
			modal="true" header="Cadastrar Local">

			<h:form prependId="false" id="frmLocNovo">
				<h:panelGrid id="pnlLocNovo" columns="2">
					<p:outputLabel value="Descrição: " for="nome2" />
					<p:inputText id="nome2" value="#{MBLocal.localDomain.descricao}"
						maxlength="50" size="40" required="true"
						requiredMessage="Campo nome obrigatório" />
				</h:panelGrid>

				<h:panelGrid columns="2">
					<p:commandButton value="Salvar"
						actionListener="#{MBLocal.saveOrUpdate}"
						update=":msgGlobal :frmLocListagem:tblLocListagem"
						oncomplete="verificar(xhr, status, args, 'dlgLocNovo', 'tabelaLocListagem')"
						onclick="PF('dlgLocNovo').hide();" />
					<p:commandButton value="Cancelar"
						onclick="PF('dlgLocNovo').hide();" process="@this">
						<p:resetInput target="pnlLocNovo" />
					</p:commandButton>
				</h:panelGrid>
			</h:form>
		</p:dialog>


		<!-- 		Final do Dialogo de inclusão -->

		<!-- 		Inicio o Dialogo de exclusão -->
		<p:dialog widgetVar="dlgLocExcluir" closable="true" draggable="false"
			closeOnEscape="true" resizable="false" appendTo="@(body)"
			modal="true" header="Excluir Cargo">

			<h:form prependId="false" id="frmLocExcluir">
				<h:panelGrid id="pnlLocExcluir" columns="2">

					<p:outputLabel value="Código: " />
					<h:outputText value="#{MBLocal.localDomain.codigo}" />

					<p:outputLabel value="Descricao: " />
					<h:outputText value="#{MBLocal.localDomain.descricao}" />
					
					<p:outputLabel value="Inativo: " />
					<h:outputText value="#{MBLocal.localDomain.inativo}" />

				</h:panelGrid>

				<h:panelGrid columns="2">
					<p:commandButton value="Excluir"
						actionListener="#{MBLocal.excluirLocal}"
						update="@all"
						oncomplete="PF('dlgLocExcluir').hide();" />
					<p:commandButton value="Cancelar"
						oncomplete="PF('dlgLocExcluir').hide();" />
				</h:panelGrid>
			</h:form>
		</p:dialog>

		<!-- Final do Dialogo de Exclusão -->

		<!-- 		Inicio do Dialogo de Atualização -->

		<p:dialog widgetVar="dlgLocAlterar" closable="true" draggable="false"
			closeOnEscape="true" resizable="false" appendTo="@(body)"
			modal="true" header="Alterar Cargo">

			<h:form prependId="false" id="frmLocAlterar">
				<h:panelGrid id="pnlLocAlterar" columns="2">

					<p:outputLabel value="Código: " />
					<h:outputText value="#{MBLocal.localDomain.codigo}" />

					<p:outputLabel for="nome1" value="Nome: " />
					<p:inputText id="nome1" value="#{MBLocal.localDomain.descricao}"
						maxlength="50" size="40" required="true"
						requiredMessage="Campo nome obrigatório" />
	
					<p:outputLabel value="Inativo: " />
					<p:selectBooleanCheckbox value="#{MBLocal.localDomain.inativo}" />

				</h:panelGrid>

				<h:panelGrid columns="2">
					<p:commandButton value="Salvar"
						actionListener="#{MBLocal.saveOrUpdate}"
						update="@all"
						oncomplete="verificar(xhr, status, args, 'dlgLocAlterar', 'tabelaCarListagem')" />
					<p:commandButton value="Cancelar"
						onclick="PF('dlgLocAlterar').hide();" process="@this">
						<p:resetInput target="pnlLocAlterar" />
					</p:commandButton>
				</h:panelGrid>
			</h:form>
		</p:dialog>

		<!-- 		Final do Dialogo de Atualização -->


	</ui:define>
</ui:composition>